/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.swirrel.listener;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import org.swirrel.util.MethodCall;
import org.swirrel.util.SwirrelException;

/**
 *
 * @author Gronau
 */
public class SwirrelWindowListener
    extends AbstractSwirrelListener implements WindowListener {

  private final MethodCall windowActivatedCall;
  private final MethodCall windowClosedCall;
  private final MethodCall windowClosingCall;
  private final MethodCall windowDeactivatedCall;
  private final MethodCall windowDeiconifiedCall;
  private final MethodCall windowIconifiedCall;
  private final MethodCall windowOpenedCall;

  public SwirrelWindowListener(
      MethodCall windowActivatedCall,
      MethodCall windowClosedCall,
      MethodCall windowClosingCall,
      MethodCall windowDeactivatedCall,
      MethodCall windowDeiconifiedCall,
      MethodCall windowIconifiedCall,
      MethodCall windowOpenedCall) {
    this.windowActivatedCall = windowActivatedCall;
    this.windowClosedCall = windowClosedCall;
    this.windowClosingCall = windowClosingCall;
    this.windowDeactivatedCall = windowDeactivatedCall;
    this.windowDeiconifiedCall = windowDeiconifiedCall;
    this.windowIconifiedCall = windowIconifiedCall;
    this.windowOpenedCall = windowOpenedCall;
    if (!checkSignature(windowActivatedCall, WindowEvent.class) ||
        !checkSignature(windowClosedCall, WindowEvent.class) ||
        !checkSignature(windowClosingCall, WindowEvent.class) ||
        !checkSignature(windowDeactivatedCall, WindowEvent.class) ||
        !checkSignature(windowDeiconifiedCall, WindowEvent.class) ||
        !checkSignature(windowIconifiedCall, WindowEvent.class) ||
        !checkSignature(windowOpenedCall, WindowEvent.class)) {
      throw new SwirrelException(
          "Method must have none or one WindowEvent argument");
    }
  }

  public void windowActivated(WindowEvent e) {
    call(windowActivatedCall, e);
  }

  public void windowClosed(WindowEvent e) {
    call(windowClosedCall, e);
  }

  public void windowClosing(WindowEvent e) {
    call(windowClosingCall, e);
  }

  public void windowDeactivated(WindowEvent e) {
    call(windowDeactivatedCall, e);
  }

  public void windowDeiconified(WindowEvent e) {
    call(windowDeiconifiedCall, e);
  }

  public void windowIconified(WindowEvent e) {
    call(windowIconifiedCall, e);
  }

  public void windowOpened(WindowEvent e) {
    call(windowOpenedCall, e);
  }
}
